<?php
namespace app\front\service\v1;
use app\front\service\GetMsgService;
use app\front\model\Notify  as NotifyModel;
class gzhCallBack extends GetMsgService
{
    public function Notify(){
        $xmlData = getPost();
        $returnParams = [
            'return_code' => 'SUCCESS',
            'return_msg'  => 'OK'
        ];
        echo ArrToXml($returnParams);
       logs("return_Notify.txt", $xmlData);
        $arr = XmlToArr($xmlData);
        logs("return_Notify.txt", $arr);
        if(checkSign($arr)){
            $notify_data = ['total_fee'=>$arr['total_fee'],'openid'=>$arr['openid'],'out_trade_no'=>$arr['out_trade_no'],'return_code'=>$arr['return_code'],'result_code'=>$arr['result_code'],'sign'=>$arr['sign'],'create_time'=>date("Y-m-d H:i:s",time())];
            NotifyModel::create($notify_data);  
           // $this->logs("notify_data.txt", $notify_data['total_fee']);
        }else{
            $TemporaryMsg=$this->getTemporaryForMchId($arr['out_trade_no']);
            $customer_id=$TemporaryMsg['open_id'];
            $store_id =$TemporaryMsg['store_id'];
            $moneyNum = $TemporaryMsg['total_fee'];
            $moneyNum= bcdiv($moneyNum,100,3);
            $this->order_add($arr['out_trade_no'],$customer_id, $store_id, $moneyNum,$statu=1,$desc='签名失败');
        }
        
    }
}

